package com.example.utils;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class RemoveBlankLinesUtils {
    public static void remove(File file) throws IOException {
            String fileName=file.getName();
            System.out.println(fileName);
            String filename = "E:\\accept_files\\new" + fileName;//filename1文件被去除空行后，放入文件filename2中
            File file1=new File(filename);
            if (file.exists()){
                file1.createNewFile();
            }
            InputStream is=null;
            BufferedReader br = null;
            String tmp;
            FileWriter writer=null;
            int i=0;

            try {
                is=new BufferedInputStream(new FileInputStream(file));
                br = new BufferedReader(new InputStreamReader(is, "utf-8"));
                writer = new FileWriter(file1, true);
                while((tmp=br.readLine())!=null){
                    if(tmp.equals(""));
                    else{
                        writer.write(tmp+"\n");
                        i++;
                        System.out.println(i);
                    }
                }
                writer.close();
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
}
